Skip to content

ARROW-3778: [C++] Compile parts of test-util.h that we can once, link with unit tests - #2997

Closed
wesm wants to merge 6 commits into
apache:masterfrom
wesm:ARROW-3778
Closed

wesm wants to merge 6 commits into
apache:masterfrom
wesm:ARROW-3778

Conversation

@wesm

@wesm wesm commented Nov 19, 2018

Copy link
Copy Markdown
Member

This has to be compiled into a separate static library and added to the link libs for the unit tests and benchmarks

Change-Id: Ic3b5292a1f385ea6a75c30c775b3411efb227534
@wesm

wesm commented Nov 20, 2018

Copy link
Copy Markdown
Member Author

This is broken on Windows, I will have a look later today

Comment thread cpp/CMakeLists.txt Outdated
if (ARROW_BUILD_TESTS OR ARROW_BUILD_BENCHMARKS)
# TODO(wesm): maybe find a better place to put shared auxiliary testing tools
# that depend on gtest
add_library(arrow_testing_aux STATIC src/arrow/test-util.cc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this must be STATIC? Maybe using OBJECT or SHARED will solve your problem on Windows, probably OBJECT is what you're looking for: compile once, link "statically" into the tests everywhere.

@wesm

wesm commented Nov 21, 2018

Copy link
Copy Markdown
Member Author

Argh, so the issue is more complex on Windows. The test utilities contain inline symbols from other Arrow headers, which seems to cause a conflict with the symbols in arrow.dll (multiply defined symbols). Since these are inline I don't really get why it's a problem. I don't know enough about linking on Windows to know how to fix this using the add_library(... OBJECT) method.

To resolve the issue, I am now building both static and shared variants of the testing helper library and linking the corresponding library depending on whether ARROW_BUILD_SHARED is on

@pitrou

pitrou commented Nov 21, 2018

Copy link
Copy Markdown
Member

Another possibility would be to compile test-util into the Arrow library (possibly inside a arrow::test namespace). That would increase the library size a bit but I think we can live with that.

@wesm

wesm commented Nov 21, 2018

Copy link
Copy Markdown
Member Author

We can't do that because the test code depends on gtest

@wesm

wesm commented Nov 21, 2018

Copy link
Copy Markdown
Member Author

We could of course make the compiled code not depend on gtest, but that would best be taken care of in another patch

@wesm

wesm commented Nov 21, 2018

Copy link
Copy Markdown
Member Author

Windows is a huge pain. The static CRT build is failing on Windows for reasons unknown. I will have to keep looking at this later today

@pitrou

pitrou commented Nov 21, 2018

Copy link
Copy Markdown
Member

I'm sure that has to do with different copies of the CRT being linked in.
I think that the approach of linking test-util into the Arrow library may help minimize such issues.

@wesm

wesm commented Nov 21, 2018

Copy link
Copy Markdown
Member Author

I'll look at removing the gtest-depending code from the object file. That will be easier for me than messing around with linker settings

@wesm

wesm commented Nov 21, 2018

Copy link
Copy Markdown
Member Author

Started looking at this. The gtest stuff is pretty inextricable. We need to have functions like AssertArraysEqual that can be used with googletest that will perform appropriate assertions.

I'll keep looking at the static CRT thing for now

@wesm

wesm commented Nov 21, 2018

Copy link
Copy Markdown
Member Author

OK, the key item is here:

https://github.com/apache/arrow/blob/master/ci/appveyor-cpp-build.bat#L24

  @rem Since we link the CRT statically, we should also disable building
  @rem the Arrow shared library to link the tests statically, otherwise
  @rem the Arrow DLL and the tests end up using a different instance of
  @rem the CRT, which wreaks havoc.

But the recent change to link the unit tests dynamically is forcing ARROW_BUILD_SHARED to be on. This is a bit hacky, so I'm going to introduce an ARROW_TESTS_LINKAGE argument so we can switch to static linkage for the tests

wesm added 2 commits November 21, 2018 12:03
…d to ON in Windows Static CRT build

Change-Id: Id84d7fcaac61d06cf78c31103b6fbbdb696ab126
Change-Id: Ic0b782d6c3d8fb9bdbdcc68e2ce2fb11e6971887
@wesm

wesm commented Nov 22, 2018

Copy link
Copy Markdown
Member Author

Merging this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants